package com.myproject.music.service.impl;
import com.myproject.music.BizException;
import com.myproject.music.domain.User;
import com.myproject.music.mapper.UserMapper;
import com.myproject.music.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserServiceImpl implements UserService {
    private static final Logger log = LoggerFactory.getLogger(UserServiceImpl.class);
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> selectUserAll() {
        return userMapper.selectUserAll();
    }

    @Override
    public User selectUserById(Long id) {
        User user =userMapper.selectUserById(id);
        if(user ==null){
            log.error("该歌手"+id+"不存在");
            throw new BizException("该歌手"+id+"不存在");
        }
        log.info("查询歌手"+id+"成功");
        return userMapper.selectUserById(id);
    }

    @Override
    public List<User> selectUserByParam(String userName) {
        return userMapper.selectUserByParam(userName);
    }

    @Override
    public int insertUser(User user) {
        return userMapper.insertUser(user);
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }

    @Override
    public int deleteUserById(Long id) {
        return userMapper.deleteUserById(id);
    }
}